package controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import pojo.User;
import service.UserService;
import utils.Result;

@Controller
@ResponseBody
@RequestMapping("/user")
@CrossOrigin


public class UserController {
   @Autowired
    private UserService userService;

    @RequestMapping("findUser/{username}/{password}")
   public Result findUser(@PathVariable("username") String username,
                          @PathVariable("password") String password){
       User user =userService.findUser(username,password);
       if (user!=null){
           return new Result(true,user);
       }
       return new Result(false);
   }


    @RequestMapping("/findall")
    public User findall(){
        return userService.findall();
    }

    @RequestMapping("/addUser")
    public Result addUser(@RequestBody User user){
        return new Result(userService.addUser(user),null);
    }
}
//{"data":{"address":"上海市普陀区金沙江路 1518 弄'",
//        "birthday":"2001-01-0108:00:00",
//        "id":"1",
//        "idcard":"12312321313123213",
//        "name":"小明"
//        ,"password":"123",
//        "phone":"123456789",
//        "state":1,
//        "username":"111"},
//        "flag":true}